package com.hy.day;

/**
 * Created With IntelliJ IDEA.
 * Descriptions:
 * <p>
 * User:Mr.Du
 * Date:2024/7/27
 * Time:16:30
 */
public class GetSmallestString {

    public static void main(String[] args) {
        String s = "zbbz";
        int k = 3;
        GetSmallestString getSmallestString = new GetSmallestString();
        System.out.println(getSmallestString.getSmallestString(s, k));

    }

    public String getSmallestString(String s, int k) {
        if(k == 0) return s;
        char[] t = s.toCharArray();
        for (int i = 0; i < t.length; i++) {
            int dis = Math.min(t[i] - 'a', 'z' - t[i] + 1);
            if (dis > k) {
                t[i] -= k;
                break;
            }
            t[i] = 'a';
            k -= dis;
        }
        return new String(t);
    }
}
